Bug 524151 - Dragging of 0-byte files results in an empty filename on
authorTor Lillqvist <tml@novell.com>
Mon, 24 Mar 2008 17:35:02 +0000 (17:35 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Mon, 24 Mar 2008 17:35:02 +0000 (17:35 +0000)
2008-03-24  Tor Lillqvist  <tml@novell.com>

Bug 524151 - Dragging of 0-byte files results in an empty filename
on Windows XP and above

* gdk/win32/gdkdnd-win32.c (resolve_link): Check for the file
being empty first. For some reason ISHellLink and IPersistFile
succeeds in interpreting empty files as shortcuts, claiming the
target of the shortcut is an empty path.

Change the function to take the wide character file name that the
caller already has anyway, to avoid a superfluous conversion from
UTF-8 to UTF-16.

svn path=/trunk/; revision=19931

ChangeLog
gdk/win32/gdkdnd-win32.c

index 2ea261f2580da9011e65c1336c2d0fe6cd00b3a5..866cffae92bfeeccec0e85bc89329e6ebb8056bc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-03-24  Tor Lillqvist  <tml@novell.com>
+
+       Bug 524151 - Dragging of 0-byte files results in an empty filename
+       on Windows XP and above
+
+       * gdk/win32/gdkdnd-win32.c (resolve_link): Check for the file
+       being empty first. For some reason ISHellLink and IPersistFile
+       succeeds in interpreting empty files as shortcuts, claiming the
+       target of the shortcut is an empty path.
+
+       Change the function to take the wide character file name that the
+       caller already has anyway, to avoid a superfluous conversion from
+       UTF-8 to UTF-16.
+
 2008-03-23  Björn Lindqvist  <bjourne@gmail.com>
 
        * gdk-pixbuf/gdk-pixbuf-io.c (gdk_pixbuf_new_from_xpm_data): Guard
index b8d940a046810aaf8e3bf88f0200b65c2fa6f6bd..d397ebf57cd73f1618718218b6904741b8e880e5 100644 (file)
@@ -851,15 +851,24 @@ enum_formats_new (void)
 
 /* From MS Knowledge Base article Q130698 */
 
-static HRESULT 
+static gboolean
 resolve_link (HWND     hWnd,
-             guchar  *lpszLinkName,
+             wchar_t *link,
              guchar **lpszPath)
 {
+  WIN32_FILE_ATTRIBUTE_DATA wfad;
   HRESULT hres;
   IShellLinkW *pslW = NULL;
   IPersistFile *ppf = NULL;
 
+  /* Check if the file is empty first because IShellLink::Resolve for
+   * some reason succeeds with an empty file and returns an empty
+   * "link target". (#524151)
+   */
+    if (!GetFileAttributesExW (link, GetFileExInfoStandard, &wfad) ||
+       (wfad.nFileSizeHigh == 0 && wfad.nFileSizeLow == 0))
+      return FALSE;
+
   /* Assume failure to start with: */
   *lpszPath = 0;
 
@@ -887,12 +896,8 @@ resolve_link (HWND     hWnd,
 
   if (SUCCEEDED (hres))
     {
-      /* Convert the given link name string to wide character string. */
-      wchar_t *wsz = g_utf8_to_utf16 (lpszLinkName, -1, NULL, NULL, NULL);
-
       /* Load the file. */
-      hres = ppf->lpVtbl->Load (ppf, wsz, STGM_READ);
-      g_free (wsz);
+      hres = ppf->lpVtbl->Load (ppf, link, STGM_READ);
     }
   
   if (SUCCEEDED (hres))
@@ -977,7 +982,7 @@ gdk_dropfiles_filter (GdkXEvent *xev,
          fileName = g_utf16_to_utf8 (wfn, -1, NULL, NULL, NULL);
 
          /* Resolve shortcuts */
-         if (resolve_link (msg->hwnd, fileName, &linkedFile))
+         if (resolve_link (msg->hwnd, wfn, &linkedFile))
            {
              uri = g_filename_to_uri (linkedFile, NULL, NULL);
              g_free (linkedFile);